package cn.kust.clock.service.impl;


import cn.kust.clock.mapper.CollectionMapper;
import cn.kust.clock.pojo.dto.CollectionDTO;
import cn.kust.clock.pojo.entity.Collection;
import cn.kust.clock.pojo.vo.CollectionVO;
import cn.kust.clock.service.CollectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


/**
 * @author YL
 * @data 2022/7/25 20:55
 **/
@Slf4j
@Service
public class CollectionServiceImpl implements CollectionService {

    @Autowired
    CollectionMapper collectionMapper;

    @Override
    public Integer updateByCollectDTO(CollectionDTO collectionDTO) {
        log.info("进入删除收藏的Service层");
        return collectionMapper.updateByCollectDTO(collectionDTO);
    }

    @Override
    public List<CollectionVO> selectClockByUserIdAndType(Long userId) {
        log.info("进入打卡收藏的Service层");
        return collectionMapper.selectClockByUserIdAndType(userId);
    }

    @Override
    public List<CollectionVO> selectTravelsByUserIdAndType(Long userId) {
        log.info("进入游记收藏的Service层");
        return collectionMapper.selectTravelsByUserIdAndType(userId);
    }

    @Override
    public List<CollectionVO> selectByUserId(Long userId) {
        log.info("进入总收藏的Service层");
        List<CollectionVO> collection1 = collectionMapper.selectClockByUserIdAndType(userId);
        List<CollectionVO> collection2 = collectionMapper.selectTravelsByUserIdAndType(userId);
        collection1.addAll(collection2);
        log.info("collection1:{}",collection1);
        return collection1;
    }

    @Override
    public Integer insert(CollectionDTO collectionDTO) {
        log.info("进入添加收藏的Service层");
        Collection collection = new Collection();
        BeanUtils.copyProperties(collectionDTO, collection);
        collection.setStatus(1);
        collection.setGmtCreate(LocalDateTime.now());
        return  collectionMapper.insert(collection);
    }
}
